package com.kish.web;

import com.kish.pojo.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

@Controller
@RequestMapping("/stu")
public class StudentController {

    @RequestMapping(value = "/all",method = RequestMethod.GET)
    @ResponseBody
    public ArrayList<Student> students(){
        ArrayList<Student> students = new ArrayList<>();
        return students;
    }


    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public Student add(Student student){
        System.out.println(student);
        return student;
    }


    @RequestMapping(value = "/one/{name}",method = RequestMethod.GET)
    @ResponseBody
    public String getOne(@PathVariable(value = "name",required = true) String name){
        System.out.println(name);
        return name;
    }

    @RequestMapping(value = "/up",method = RequestMethod.POST)
    @ResponseBody
    public String uploadFile(String name,MultipartFile uploadFile) throws IOException {
        //获得文件名称
        String originalFilename = uploadFile.getOriginalFilename();
//保存文件
        uploadFile.transferTo(new File("D:\\upload\\"+originalFilename));
        return "";
    }
}
